# # accounts/views/culture.py
# from django.shortcuts import render, redirect, get_object_or_404
# from django.contrib.auth.decorators import login_required, user_passes_test
# from django.core.paginator import Paginator
# from django.contrib import messages
# from tourist_spot.models import TouristSpot
# # from tourist_spot.forms import TouristSpotForm
#
#
# def is_culture(user):
#     return user.is_authenticated and user.user_type == 'culture'
#
#
# @login_required
# @user_passes_test(is_culture)
# def dashboard(request):
#     """文旅机构仪表盘"""
#     spots = TouristSpot.objects.filter(
#         created_by=request.user
#     ).order_by('-created_at')[:5]
#
#     stats = {
#         'total_spots': TouristSpot.objects.filter(created_by=request.user).count(),
#         'approved_spots': TouristSpot.objects.filter(
#             created_by=request.user,
#             status='approved'
#         ).count(),
#         'pending_spots': TouristSpot.objects.filter(
#             created_by=request.user,
#             status='pending'
#         ).count(),
#         'latest_spots': spots
#     }
#     return render(request, 'culture/dashboard.html', stats)
#
#
# @login_required
# @user_passes_test(is_culture)
# def spot_list(request):
#     """景点列表"""
#     spots = TouristSpot.objects.filter(
#         created_by=request.user
#     ).order_by('-created_at')
#
#     paginator = Paginator(spots, 10)
#     page_number = request.GET.get('page')
#     page_obj = paginator.get_page(page_number)
#     return render(request, 'culture/spot_list.html', {'page_obj': page_obj})
#
#
# @login_required
# @user_passes_test(is_culture)
# def add_spot(request):
#     """添加景点"""
#     if request.method == 'POST':
#         form = TouristSpotForm(request.POST, request.FILES)
#         if form.is_valid():
#             spot = form.save(commit=False)
#             spot.created_by = request.user
#             spot.save()
#             messages.success(request, '景点已提交审核')
#             return redirect('culture:spot_list')
#     else:
#         form = TouristSpotForm()
#     return render(request, 'culture/add_spot.html', {'form': form})
#
#
# @login_required
# @user_passes_test(is_culture)
# def edit_spot(request, spot_id):
#     """编辑景点"""
#     spot = get_object_or_404(TouristSpot, pk=spot_id, created_by=request.user)
#     if request.method == 'POST':
#         form = TouristSpotForm(request.POST, request.FILES, instance=spot)
#         if form.is_valid():
#             # 编辑后状态重置为待审核
#             spot = form.save(commit=False)
#             spot.status = 'pending'
#             spot.save()
#             messages.success(request, '景点修改已提交重新审核')
#             return redirect('culture:spot_list')
#     else:
#         form = TouristSpotForm(instance=spot)
#     return render(request, 'culture/edit_spot.html', {'form': form, 'spot': spot})